import AmapWX from './map-sdk/amap-wx.js'
var amapKey='83dd75107efbb10605ef3f89c4f76527'

/**
 * 百度地图---->高德地图
 * @param double lat 纬度
 * @param double lng 经度
 * @return Object;
 */
export function bMapToAMap(lat, lng){
    let x_pi = Math.PI * 3000.0 / 180.0;
    let x = lng - 0.0065;
    let y = lat - 0.006;
    let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
    let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
    lng = z * Math.cos(theta);
    lat = z * Math.sin(theta);
	return {'lng':lng, 'lat':lat}
}

/**
 * 获取POI信息(周边分类信息)
 */
export function getPoiAround(lng, lat, keywords, callback) {
	const amapPlugin = new AmapWX.AMapWX({
		key: amapKey
	})
	
	amapPlugin.getPoiAround({
		location: lat + ',' + lng, // location的格式为'经度,纬度'
		querykeywords:keywords,
		// 成功回调
		success: function(res) {
			let data = []
			for (var i = 0; i < res.poisData.length; i++) {
				data.push({ // 获取返回结果
					title: res.poisData[i].name,
					lat: res.poisData[i].latitude,
					lng: res.poisData[i].longitude,
					address: res.poisData[i].address,
					distance: res.poisData[i].distance,
					// iconPath: "/resources/my_marker.png", //图标路径
					// width: 20,
					// height: 20
				})
			}
			callback(data)
		},
		fail: function(info) {
			// 失败回调
			// console.log(info)
		}
	})
}

export default {
	bMapToAMap,
	getPoiAround
}